package com.netease.financial.common.util;

import android.content.Context;
import android.widget.Toast;

import com.netease.financial.common.util.preferences.DebugPreferencesHelper;

/**
 * @author yufeng.wu
 */
public class ToastUtils {

    private static Toast sToast;

    public static void showShort(Context context, CharSequence text) {
        if (sToast != null) {
            sToast.cancel();
        }
        sToast = Toast.makeText(context , text, Toast.LENGTH_SHORT);
        sToast.show();
    }

    public static void showShort(Context context, int resId) {
        if (sToast != null) {
            sToast.cancel();
        }
        sToast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
        sToast.show();
    }

    public static void showLong(Context context, CharSequence text) {
        if (sToast != null) {
            sToast.cancel();
        }
        sToast = Toast.makeText(context, text, Toast.LENGTH_LONG);
        sToast.show();
    }

    public static void showLong(Context context, int resId) {
        if (sToast != null) {
            sToast.cancel();
        }
        sToast = Toast.makeText(context, resId, Toast.LENGTH_LONG);
        sToast.show();
    }

    public static void showDebugToast(Context context, CharSequence text) {
        if (getToastDebugMode(context)) {
            showLong(context, text);
        }
    }

    public static void showDebugToast(Context context, int resId) {
        if (getToastDebugMode(context)) {
            showLong(context, resId);
        }
    }

    private static boolean getToastDebugMode(Context context) {
        return NfsLog.DEBUG_MODE && DebugPreferencesHelper.isToastDebugOpen();
    }
}
